<!DOCTYPE html> 
<!--
 Copyright (c) 2014, 2017 University of Thessaloniki, fortiss GmbH
  
 This program and the accompanying materials are made available under the
 terms of the Eclipse Public License 2.0 which is available at
 http://www.eclipse.org/legal/epl-2.0.

 SPDX-License-Identifier: EPL-2.0
 
 Contributors:
   Giorgis Sfiris, Monika Wenger, Alois Zoitl, Jose Cabral
     - initial API and implementation and/or initial documentation
-->


<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>FBDK/IP</title>
	<link rel="stylesheet" type="text/css" href="../help.css">
</head>

<body>
<h1 id="topOfPage">FBDK/IP</h1>
<p>This section will show you how to make applications communicate using the default FBDK/ip protocol as defined in the <a href="http://holobloc.com/doc/ita/index.htm" target="_blank">IEC 61499 Compliance Profile for Feasibility Demonstrations</a>. Because we are going to use the default protocol, we don't have to put it as a parameter in the beginning of the ID input of the Communication Function Blocks. We only have to provide an IP address and port in the following format:</p>
	
<div class="code">address:port</div>

<p>So an ID like: </p>
	
<div class="code">192.168.0.2:61499</div>

<p>will be automatically converted into this:</p>

<div class="code">fbdk[].ip[192.168.0.2:61499]</div>

<h2 id="publishSubscribe">Publish/Subscribe - UDP/IP</h2>

<p>To communicate using Publish/Subscribe FBs, a UDP/IP connection is utilized, so we have to provide the Publish/Subscribe Function Blocks with a multicast IP address and a port. The Publish FBs will send data over the network in this multicast IP address/port and the Subscribe FBs will listen to the same multicast IP address/port receiving any data sent by the Publish FBs. Multicast IP addresses can be picked from the range 224.0.0.0 - 239.255.255.255, while the port is arbitrary. So an example ID parameter for the Publish/Subscribe FBs would be:</p>
	
<div class="code">225.0.0.1:61499</div>

<p>In contrast to Client/Server pairs (see <a href="#clientServer">next section</a>), Publish/Subscribe FBs don't have to work in pairs. Any Subscribe FB in any device listening to this multicast IP address will receive data sent by any Publish FB in this multicast IP address.</p>

<p>An example of using a Publish/Subscribe FBs can be seen in the figure below and can be summarized as follows:</p>

<ol>
	<li>After a delay of 10 seconds, integer 2 is sent over UDP on the multicast IP address 225.0.0.1 and port 61500 by the first device (red).</li>
	<li>The second device (green) receives the integer by listening to the same multicast IP address.</li>
	<li>The second device increases the received integer by 3.</li>
	<li>The second device sends the result over UDP on the multicast IP address 225.0.0.1 and port 61499.</li>
	<li>The first device receives the result by listening to the same multicast IP address.</li>
</ol>

<p>Note that</p>
<ul>
	<li>each Publish FB has the same number of inputs as the number of outputs of the corresponding Subscribe FB.</li>
	<li>each Publish/Subscribe pair has its own unique multicast IP address and port.</li>
	<li>a unique port number in each Publish/Subscribe pair is enough for the two pairs not to interfere with each other.</li>
	<li>the RSP event input of Subscribe FBs is not used, while the CNF event output of Publish FBs is set directly (see Client/Server pairs)</li>
	<li>as mentioned above, Publish and Subscribe FBs don't have to work in pairs. Any data sent in a particular multicast IP address by any Publish FB will be received by any Subscribe FB listening to that multicast IP address.</li>
</ul>

<img src="../../html/communication/img/publishsubscribe.png" alt="Publish/Subscribe pair"/>


<h2 id="clientServer">Client/Server - TCP/IP</h2>

<p>To communicate using a Client/Server pair, a TCP/IP connection is utilized, so we have to set a Server in one device listening to a certain port and have a Client in another device connect to this Server using the first device's IP address and Server's listening port. The Client FB will send a request to the Server FB using the Server FB's IP address and port and the Server FB will respond after processing the received data. So if the Server is running in a device with IP address 192.168.0.2 listening to port 61501, an example of the ID parameters used for the Client/Server pair would be:</p>

<p>Server</p>
	
<div class="code">localhost:61501</div>

<p>Client</p>

<div class="code">192.168.0.2:61501</div>

<p>However the "localhost" attribute is just for informational reasons and will not be used by FORTE, i.e. the Server's IP address will always be the same as the device's IP address. Only the port attribute is used. In contrast to Publish/Subscribe FBs, Client/Server FBs work in pairs. Only one Client FB can be connected to a Server FB at a time, while a Client FB can be connected to only one Server FB.</p>

<p>An example of using a Client/Server pair can be seen in the figure below and can be summarized as follows:</p>

<ol>
	<li>After a delay of 15 seconds the CLIENT_1 FB in the first device (orange) is initialized.</li>
	<li>A request is send to the second device (teal), using the second device's IP address (192.168.0.2) and port 61505 used by SERVER_1 FB.</li>
	<li>The second device receives integer 5.</li>
	<li>After a delay of 3 seconds the second device sends a response back to the first device.</li>
	<li>The first device receives integer 3 in CLIENT_1 FB.</li>
	<li>After a delay of 3 seconds the CLIENT_1 FB in the first device is terminated.</li>
	<li>After 25 seconds from the start the CLIENT_2 FB in the first device is initialized.</li>
	<li>A request is send to the second device, using the same IP address and port as before.</li>
	<li>The second device receives integer 8.</li>
	<li>After a delay of 3 seconds the second device sends a response back to the first device.</li>
	<li>The first device receives integer 3 in CLIENT_2 FB.</li>
</ol>

<p>Note that</p>
<ul>
	<li>each Client FB has the same number of inputs and outputs as the number of inputs and outputs of the corresponding Server FB.</li>
	<li>the response to the Client FBs has to be triggered to the Server FB, it is not sent automatically</li>
	<li>SERVER_1 FB must be initialized before CLIENT_1 and CLIENT_2 FBs so that they can connect to it.</li>
	<li>CLIENT_1 FB must be terminated before CLIENT_2 FB can connect to the SERVER_1 FB, i.e. the Server can serve only one Client at a time.</li>
</ul>

<img src="../../html/communication/img/clientserver.png" alt="Client/Server pair"/>

<h1>Where to go from here?</h1>

<p>Go back to Protocols index:</p>

<p><a href="../../html/communication/communicationIndex.html">Communication Index</a></p>

<p>If you want to go back to the Start Here page, we leave you here a fast access</p>

<p><a href="../../html/startHere/startHere.html">Start Here page</a></p>

<p class="goToTop">Or <a href="#topOfPage">Go to top</a></p>

</body>
</html>